define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'fastim/report/index' + location.search,
                    add_url: 'fastim/report/add',
                    edit_url: 'fastim/report/edit',
                    del_url: 'fastim/report/del',
                    multi_url: 'fastim/report/multi',
                    import_url: 'fastim/report/import',
                    table: 'fastim_report',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'type',
                            title: __('Type'),
                            searchList: {
                                "user": __('Type user'),
                                "group": __('Type group'),
                                "feedback": __('Type feedback')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'report_id', title: __('Report_id') + 'ID', placeholder: 'IM用户ID'},
                        {field: 'nickname', title: __('Report_id'), operate: false},
                        // {field: 'session_id', title: __('Session_id')},
                        {
                            field: 'user.nickname',
                            title: __('User_id'),
                            operate: false,
                            formatter: Controller.api.formatter.user
                        },
                        {field: 'user_id', title: __('User_id') + 'ID', visible: false},
                        {field: 'describe', title: __('Describe'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {
                            field: 'reportimage',
                            title: __('Reportimage'),
                            operate: false,
                            events: Table.api.events.image,
                            formatter: Table.api.formatter.images
                        },
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {"0": __('Status 0'), "1": __('Status 1')},
                            formatter: Table.api.formatter.status
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                user: function (value, row, index) {
                    return value == '-' ? value : value + '(ID:' + row.user_id + ')'
                }
            }
        }
    };
    return Controller;
});